﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class YHJ_DAL
    {
        public YHJ_DAL(Context context)
        {
            Context = context;
        }

        public Context Context { get; }

        /// <summary>
        /// 优惠劵添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public  int  YHJAdd(YHJ_Model m)
        {
            var m1=Context.YHJ_Model.FirstOrDefault(x=>x.YName==m.YName);
            if(m1!=null)
            {
                return -1;
            }
            else
            {
                Context.YHJ_Model.Add(m);
                return Context.SaveChanges();   
            }
        }
        /// <summary>
        /// 优惠劵列表
        /// </summary>
        /// <returns></returns>
        public List<YHJ_Model> YHJShow()
        {
            return Context.YHJ_Model.AsQueryable().ToList();

        }
    }
}
